package jp.yvn.game.shooting.schedule;

import jp.yvn.game.shooting.R;
import jp.yvn.game.shooting.element.EnemyFairy1Entity;
import jp.yvn.game.shooting.element.EnemyFairy2Entity;
import jp.yvn.game.shooting.element.TelopEntity;
import jp.yvn.game.shooting.logic.StageLogic;
import jp.yvn.game.shooting.util.Const;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.PointF;

/**
 * Nomal mode Stage1のｽｹｼﾞｭｰﾙｸﾗｽです
 * 
 * @author Yvn_pq
 */
public class NomalStage1Stage extends BaseStageSchedule {

	private final long[] EVENT_TIMING = { 3000, 5000, 8000, 12000, 15000, 18000, 21000, 25000 };

	private final int mEventCnt = 0;

	private long mStartTime = 0;

	private TelopEntity mTelop;

	public NomalStage1Stage(Context context, Point viewSize) {
		super(context, viewSize);

		// 初期化
		Resources res = mContext.getResources();

		mBulletBitmap = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(res, R.drawable.ring_blue_001), Const.BULLET_BLUE_SIZE, Const.BULLET_BLUE_SIZE, true);

		// 敵フェアリー１画像(右向き)読込
		for (int i = 0; i < BMP_FAIRY1_RIGHT_ID.length; i++) {
			mFairy1RightBitmapList[i] = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(res, BMP_FAIRY1_RIGHT_ID[i]), Const.FAIRY_WIDTH, Const.FAIRY_HEIGHT, true);
		}

		// 敵フェアリー１画像(左向き)読込
		for (int i = 0; i < BMP_FAIRY1_RIGHT_ID.length; i++) {
			mFairy1LeftBitmapList[i] = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(res, BMP_FAIRY1_LEFT_ID[i]), Const.FAIRY_WIDTH, Const.FAIRY_HEIGHT, true);
		}

		// 敵フェアリー１画像(正面)読込
		for (int i = 0; i < BMP_FAIRY1_FRONT_ID.length; i++) {
			mFairy1FrontBitmapList[i] = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(res, BMP_FAIRY1_FRONT_ID[i]), Const.FAIRY_WIDTH, Const.FAIRY_HEIGHT, true);
		}

		// 敵フェアリー２画像(右向き)読込
		for (int i = 0; i < BMP_FAIRY2_RIGHT_ID.length; i++) {
			mFairy2RightBitmapList[i] = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(res, BMP_FAIRY2_RIGHT_ID[i]), Const.FAIRY_WIDTH, Const.FAIRY_HEIGHT, true);
		}

		// 敵フェアリー２画像(左向き)読込
		for (int i = 0; i < BMP_FAIRY1_RIGHT_ID.length; i++) {
			mFairy2LeftBitmapList[i] = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(res, BMP_FAIRY2_LEFT_ID[i]), Const.FAIRY_WIDTH, Const.FAIRY_HEIGHT, true);
		}

		// 敵フェアリー２画像(正面)読込
		for (int i = 0; i < BMP_FAIRY2_FRONT_ID.length; i++) {
			mFairy2FrontBitmapList[i] = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(res, BMP_FAIRY2_FRONT_ID[i]), Const.FAIRY_WIDTH, Const.FAIRY_HEIGHT, true);
		}

		createEnemy(context, viewSize);

		mStartTime = System.currentTimeMillis();
	}

	private final void createEnemy(Context context, Point viewSize) {
		// テロップ
		mTelop = new TelopEntity(context, TelopEntity.NOMAL_STG_1, viewSize);

		// 敵
		StageLogic.enemyList.add(new EnemyFairy1Entity(context, new PointF(-10.0f, -50), new PointF(viewSize.x, -50), viewSize));
		// enemyList.add(new EnemyFairy1Entity(context, new PointF(viewSize.x,
		// -50), new PointF(-10.0f, -50), viewSize));
		// enemyList.add(new EnemyFairy1Entity(context, new PointF(-10.0f, 20),
		// new PointF(viewSize.x, 20), viewSize));
		// enemyList.add(new EnemyFairy1Entity(context, new PointF(viewSize.x,
		// 20), new PointF(-10.0f, 20), viewSize));
		// enemyList.add(new EnemyFairy1Entity(context, new PointF(-10.0f, i *
		// 30), new PointF(viewSize.x, i * 30), viewSize));
		// enemyList.add(new EnemyFairy1Entity(context, new PointF(viewSize.x, i
		// * 30), new PointF(-10.0f, i * 30), viewSize));
		// enemyList.add(new EnemyFairy1Entity(context, new PointF(-10.0f, i *
		// 40), new PointF(viewSize.x, i * 40), viewSize));
		// enemyList.add(new EnemyFairy1Entity(context, new PointF(viewSize.x, i
		// * 40), new PointF(-10.0f, i * 40), viewSize));
		// enemyList.add(new EnemyFairy1Entity(context, new PointF(-10.0f, i *
		// 50), new PointF(viewSize.x, i * 50), viewSize));
		// enemyList.add(new EnemyFairy1Entity(context, new PointF(viewSize.x, i
		// * 50), new PointF(-10.0f, i * 50), viewSize));
		// i++;
		StageLogic.enemyList.add(new EnemyFairy2Entity(context, new PointF(-10.0f, 50), new PointF(viewSize.x, 20), viewSize));
		StageLogic.enemyList.add(new EnemyFairy2Entity(context, new PointF(viewSize.x, 20), new PointF(-10.0f, 50), viewSize));
		// enemyList.add(new EnemyFairy2Entity(context, new PointF(-10.0f,
		// starty + i * 15), new PointF(viewSize.x, endy + i * 15), viewSize));
		// enemyList.add(new EnemyFairy2Entity(context, new PointF(viewSize.x,
		// endy + i * 15), new PointF(-10.0f, starty + i * 15), viewSize));
		// enemyList.add(new EnemyFairy2Entity(context, new PointF(-10.0f,
		// starty + i * 20), new PointF(viewSize.x, endy + i * 20), viewSize));
		// enemyList.add(new EnemyFairy2Entity(context, new PointF(viewSize.x,
		// endy + i * 20), new PointF(-10.0f, starty + i * 20), viewSize));
		// enemyList.add(new EnemyFairy2Entity(context, new PointF(-10.0f,
		// starty + i * 25), new PointF(viewSize.x, endy + i * 25), viewSize));
		// enemyList.add(new EnemyFairy2Entity(context, new PointF(viewSize.x,
		// endy + i * 25), new PointF(-10.0f, starty + i * 25), viewSize));
		// enemyList.add(new EnemyFairy2Entity(context, new PointF(-10.0f,
		// starty + i * 30), new PointF(viewSize.x, endy + i * 30), viewSize));
		// enemyList.add(new EnemyFairy2Entity(context, new PointF(viewSize.x,
		// endy + i * 30), new PointF(-10.0f, starty + i * 30), viewSize));
		// i++;
		// enemyList.add(new EnemyFairy1Entity(context, new PointF(-10.0f, i *
		// 20), new PointF(viewSize.x, i * 20), viewSize));
		// enemyList.add(new EnemyFairy1Entity(context, new PointF(viewSize.x, i
		// * 20), new PointF(-10.0f, i * 20), viewSize));
		// enemyList.add(new EnemyFairy1Entity(context, new PointF(-10.0f, i *
		// 20), new PointF(viewSize.x, i * 20), viewSize));
		// enemyList.add(new EnemyFairy1Entity(context, new PointF(viewSize.x, i
		// * 20), new PointF(-10.0f, i * 20), viewSize));
		// enemyList.add(new EnemyFairy1Entity(context, new PointF(-10.0f, i *
		// 20), new PointF(viewSize.x, i * 20), viewSize));
		// enemyList.add(new EnemyFairy1Entity(context, new PointF(viewSize.x, i
		// * 20), new PointF(-10.0f, i * 20), viewSize));
		// enemyList.add(new EnemyFairy1Entity(context, new PointF(-10.0f, i *
		// 20), new PointF(viewSize.x, i * 20), viewSize));
		// enemyList.add(new EnemyFairy1Entity(context, new PointF(viewSize.x, i
		// * 20), new PointF(-10.0f, i * 20), viewSize));
		// enemyList.add(new EnemyFairy1Entity(context, new PointF(-10.0f, i *
		// 20), new PointF(viewSize.x, i * 20), viewSize));
		// enemyList.add(new EnemyFairy1Entity(context, new PointF(viewSize.x, i
		// * 20), new PointF(-10.0f, i * 20), viewSize));
		// enemyList.add(new EnemyFairy1Entity(context, new PointF(-10.0f, i *
		// 20), new PointF(viewSize.x, i * 20), viewSize));
		// enemyList.add(new EnemyFairy1Entity(context, new PointF(viewSize.x, i
		// * 20), new PointF(-10.0f, i * 20), viewSize));
		// i++;
		StageLogic.enemyList.get(mEventCnt).setBefavior();
		for (int j = 0; j < StageLogic.enemyList.size(); j++) {
			StageLogic.enemyList.get(j).setBefavior();
		}
	}

	/**
	 * 描画します
	 * 
	 * @param canvas
	 */
	@Override
	public void draw(Canvas canvas) {
		// mTelop.draw(canvas);
		// if (mEventCnt < EVENT_TIMING.length - 1 && EVENT_TIMING[mEventCnt] <
		// System.currentTimeMillis() - mStartTime) {
		// BaseEnemyEntity enemy = enemyList.get(mEventCnt);
		// enemy.setBefavior();
		// mEventCnt++;
		// }
		// System.out.println("mEventCnt" + mEventCnt);
		// System.out.println("System.currentTimeMillis() - mStartTime" +
		// (System.currentTimeMillis() - mStartTime));
		for (int i = 0; i < StageLogic.enemyList.size(); i++) {
			if (!StageLogic.enemyList.get(i).alive) {
				StageLogic.enemyList.remove(i);
			} else {
				StageLogic.enemyList.get(i).fireBullet();
				StageLogic.enemyList.get(i).draw(canvas);
			}
		}
		for (int i = 0; i < StageLogic.bulletList.size(); i++) {
			if (StageLogic.bulletList.get(i).isOutsideView()) {
				StageLogic.bulletList.remove(i);
			} else {
				StageLogic.bulletList.get(i).draw(canvas, mBulletBitmap);
			}
		}
	}
}
